/*This file is part of AENIMA. AENIMA is a module of BCI++ framework for the implementation of brain computerinterface systems. 
AEnima is intended for use with BCI++ only.

BCI++ is a project of the Sensibilab of the Politecnico di Milano. 

AENIMA is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as 
published by the Free Software Foundation, either version 3 of 
the License, or (at your option) any later version.

AENIMA is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU General Public License
and the GNU Lesser General Public License along with AENIMA.  
If not, see <http://www.gnu.org/licenses/>.*/

/*!
	\file	DealProtocol.h
	 Class for the protocol management.

	\author	SensibilabE-Mail: info.sensibilab@polimi.it

	\date	2007-09-06 creation \n
		2009-01-27 last modification

	\b COPYRIGHT: 
		This program is property of Sensibilab - Campus Ponit - Lecco
*/

#pragma once

#include <iostream>
#include <stdio.h>
#include "ProtocolMngr.h"
#include "DealProtType.h"

#include "SocketComm.h"
#include "Led\LedDriver.h"
#include "SoundSystem.h"
#include "GraphicEngine.h"

typedef struct Protocols{
	char protocolName[255];
	char dllProtocol[255];
} Protocols;

class ProtocolMngr;
/*!\class DealProtocol
Class for the protocol management (in this function Critical Section are used).*/
class DealProtocol: public DealProtType
{
public:
	DealProtocol(GraphicEngine* , SoundSystem*, SocketComm*, LedDriver*);
	~DealProtocol(void);
public:
	/*!\fn bool runProtocol(char *name)
	Function to select the protocol to start ad aenima startup. The protocol is selected in the AEnima command
	line and it can be only protocol presents into Protocols.txt file.*/
	bool runProtocol(char *protocollo, bool startup);
	/*!\fn void changeProtocol(char *name, bool startup)
	Function to change active protocol.
	\param startup If true, reset engine.*/
	void changeProtocol(char *name, bool startup);
	/*!\fn void EvalProt(void)
	Function for the update and evaluation of the active protocol.*/
	void EvalProt(void);
	void RunIntoWhile(void);
	bool StartProt(void);
	bool StopProt(void);
	void OnProtocolEvent(void);
	void OnSocketEvent(BCIMessage *SocketMsg);
public:
	/// INSERTED FOR DLL
	HINSTANCE hLib;
	typedef	ProtocolMngr* (__cdecl *hGetNewProtocol)(GraphicEngine_base *Engine, SoundSystem_base *Sound, SocketComm_base *pSocket, LedDriver_base *myLed, bool startup, DealProtType *pParent);
	typedef void (_cdecl *hReleaseProtocol)(ProtocolMngr *pProt);
	//typedef void (_cdecl *hEvalProt)(void);
	hGetNewProtocol pGetNewProtocol;
	hReleaseProtocol pReleaseProtocol;
	//hEvalProt pEvalProt;
	HANDLE ghMutex;
	
	ProtocolMngr *pProtocol;
	Protocols Protocolli[255];
	int dllCont;
};